> ## Documentation Index
> Fetch the complete documentation index at: https://docs.onecortex.io/llms.txt
> Use this file to discover all available pages before exploring further.

# LlamaIndex

> Deploy a LlamaIndex FunctionAgent or AgentWorkflow as it is: streamed text, tool calls and results, and each agent as a step.

## What is supported

`llama-index-core` 0.14 and later. Onecortex recognises an `AgentWorkflow` or a `FunctionAgent` and streams its run.

## A complete agent

```yaml agent.yml theme={null}
apiVersion: v1
runtime: python3.12
entrypoint: agent.py:agent
dependencies: requirements.txt
```

```text requirements.txt theme={null}
llama-index-core>=0.14
llama-index-llms-openai
```

```python agent.py theme={null}
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI


def word_count(text: str) -> int:
    """Counts the words in a piece of text."""
    return len(text.split())


# Reads OPENAI_API_KEY, which you add as a secret on the agent's Config tab.
agent = FunctionAgent(
    tools=[word_count],
    llm=OpenAI(model="gpt-5"),
    system_prompt="Count the words in what the user says, then answer.",
)
```

Add `OPENAI_API_KEY` as a secret on the agent's **Config** tab, then deploy. Any model works: this one is an example. See [Configuration and secrets](/build/configuration).

<Card title="A complete LlamaIndex example" icon="github" href="https://github.com/onecortex-io/examples/tree/main/docs-qa">
  `docs-qa`: A documentation assistant searching pages in its folder and citing the one it used. It runs with no model key.
</Card>

## The prompt and the reply

The prompt is the run's user message. The reply is the streamed answer.

## Events it reports

| Events | From |
| - | - |
| `text` | The streamed answer |
| `tool_call_start`, `tool_call_args`, `tool_call_end` | Each tool call |
| `tool_result` | Each tool's output |
| `step_start`, `step_end` | Each agent in a workflow, by name |
| `done` or `error` | The end of the run: always exactly one |

See [Streaming and events](/build/streaming).

## The caller's fields

In the workflow context's store, under `onecortex`. A tool that declares a `Context` parameter reads it:

```python theme={null}
from llama_index.core.workflow import Context


async def search_docs(ctx: Context, query: str) -> str:
    sent = await ctx.store.get("onecortex", default={})
    detail = sent.get("params", {}).get("detail", "short")
    ...
```

## Known limits

* Each call starts a new workflow context: context state does not carry from one call to the next.

## Troubleshooting

| You see | Do this |
| - | - |
| A question outside your index returns nothing useful | That is the retrieval, not Onecortex: check the index is built at import, from files in the agent folder. |

More on [Troubleshooting](/production/troubleshooting) and [Errors](/production/errors).
