Skip to content

fix(examples): reuse existing LLM instance in langchain_react_agent.py#274

Open
verseon0980 wants to merge 1 commit intoOpenGradient:mainfrom
verseon0980:fix/langchain-agent-duplicate-llm-instance
Open

fix(examples): reuse existing LLM instance in langchain_react_agent.py#274
verseon0980 wants to merge 1 commit intoOpenGradient:mainfrom
verseon0980:fix/langchain-agent-duplicate-llm-instance

Conversation

@verseon0980
Copy link
Copy Markdown

Problem

examples/langchain_react_agent.py creates two separate LLM instances
using the same private key:

llm_client = og.LLM(private_key=private_key)
llm_client.ensure_opg_approval(min_allowance=5)

llm = og.agents.langchain_adapter(
    private_key=private_key,   # creates a second LLM internally
    ...
)

Each og.LLM() constructor makes a blocking on-chain RPC call to the
TEE registry to set up the connection. Calling it twice with the same
private key means the example triggers double the blockchain connections
and double the registry lookups for no reason.

og.agents.langchain_adapter() already accepts a client= parameter
specifically designed to receive an existing LLM instance. The
private_key= parameter is only needed when no existing client is passed.
Passing both means the existing client is ignored and a brand new one
is created internally anyway.

Affected file:

  • examples/langchain_react_agent.py lines 21-26

Fix

Pass the already-created llm_client instance directly to
langchain_adapter() via the client= parameter instead of passing
private_key= again. This reuses the existing connection with zero
extra RPC calls.

Changes

  • examples/langchain_react_agent.py: replaced private_key=private_key
    argument in langchain_adapter() with client=llm_client

Signed-off-by: verseon0980 <klokrc74@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant