> ## Documentation Index
> Fetch the complete documentation index at: https://cognitio-agent.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Function: query()

> Generated from the public TypeScript API.

```ts theme={null}
function query(input): AgentStream;
```

Create a lazy one-shot Agent query.

The private Agent is closed when iteration completes, fails, is returned
early, or `close()` is called. Its canonical server remains process-global;
use `shutdown()` for global teardown. Startup is lazy, so a never-consumed
query allocates no session; call `close()` when abandoning a started handle.

A fresh dedicated isolated server cannot reach a session stored by another
server. For resume/fork, use the canonical client, `baseUrl`, an injected
client, or `spawn: { isolated: false }`.

## Parameters

### input

Prompt and flat facade options.

#### options?

[`QueryOptions`](../interfaces/QueryOptions)

#### prompt

[`PromptInput`](../type-aliases/PromptInput)

## Returns

[`AgentStream`](../interfaces/AgentStream)

A synchronous, lazy Agent stream.

## Throws

Synchronously for invalid options or unsupported resume/fork combinations.

## Example

```ts theme={null}
import { query } from "cognitio-agent-sdk"

for await (const message of query({ prompt: "What is 2+2?" })) {
  if (message.type === "result") console.log(message.text)
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.