ag-ui-protocol / ag-ui-protocol/ag-ui

Issue: configurable values not being applied to agent config on Python backend

Aperta
#571 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug Integration
Lingua principale
Python
Stelle
15.9k
Fork
1.4k
Merge medio
1g 17h
PR unite (30g)
163

Descrizione

#### Description

When sending `configurable` values from our frontend (Next.js) through the CopilotKit SDK, they successfully appear in the request payload to the backend — but the Python agent (`LangGraphAGUIAgent`) does **not apply them** to its `runnable_config`.

The frontend correctly includes the `configurable` object in `agentState`, and the backend receives it under:

```json
{
"forward_props": {
"config": {
"configurable": {
"user_id": "user_123",
}
}
}
}
```

However, `LangGraphAGUIAgent` does not automatically read or merge these values into its config during execution.

---

### Setup

**Frontend**

```json
"@copilotkit/react-core": "1.9.3",
"@copilotkit/react-ui": "1.9.3",
"@copilotkit/runtime": "1.9.3"
```

**Framework:** Next.js (Pages Router)

```ts
const { state, setState } = useCoAgent({
name: agentName,
initialState: {
organization: { id: userId, name: data.name },
},
config: {
configurable: {
user_id: userId,
},
},
});
```

**Backend**

```python
add_langgraph_fastapi_endpoint(
app,
LangGraphAGUIAgent(
name="agent",
description="Agent description",
graph=compiled_graph,
config={"callbacks": some_callbacks, "metadata": some_metadata},
),
"/agent_endpoint",
)
```

**Python Versions**

```
copilotkit: 0.1.69
langgraph: 0.6.10
```

---

### Investigation

* The `configurable` object is **present in `forward_props.config.configurable`**, but the `LangGraphAGUIAgent` does not extract or merge it into the agent’s runtime config.
* This means runtime-specific configuration (like `user_id`, etc.) isn’t accessible inside the agent execution, even though the data is transmitted correctly.

---

### Workaround (Temporary Fix)

We implemented a custom subclass to merge the forwarded configuration before invoking the base `prepare_stream`:

```python
class CustomLangGraphAGUIAgent(LangGraphAGUIAgent):
async def prepare_stream(
self, input: RunAgentInput, agent_state: State, config: RunnableConfig
):
forwarded_props = input.forwarded_props or {}
runtime_configurable = forwarded_props.get("config", {}).get("configurable", {})
config["configurable"] = {
**(config.get("configurable", {})),
**runtime_configurable,
}
return await super().prepare_stream(input, agent_state, config)
```

This solution works — the `configurable` values are now correctly available at runtime — but since runtime configuration is a fairly standard pattern, it seems like there might be an intended or more official way to handle this.

---

### Question

* Is there a **recommended method or built-in mechanism** in CopilotKit or LangGraph for passing runtime configuration (like `configurable`) from the frontend to the Python agent?
* Alternatively, if `context` is the new preferred mechanism in `langgraph>=0.5`, could you share how to properly pass that from the frontend via the Copilot SDK?

Thanks in advance for your help!

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.