Context-Aware Agent
A local ReAct assistant that checks context and chooses tools.
Personal project
- Context tools
- 4
- ReAct iteration limit
- 5
- Interfaces
- Flask + CLI
- Default Ollama model
- llama3
LangChain · Ollama · Flask
View repositoryThe idea
I built this assistant around a small question: when I paste background into a chat, how does the model decide which parts to use? I gave the Flask interface and the terminal loop access to the same local model so I could try the same question through either one.
How a question reaches the local model
What happens when the answer falls short
I gave the runner four tools. A question with pasted notes can use the context checks. A question that needs outside information can use search. The model decides which tools to call.
- Wikipedia is the default search source.
- The executor stops after five iterations.
- Flask can try the smart and manual workflows if the first answer fails its checks.
A closer look at the code
Choose and probe the local model
This excerpt selects the configured Ollama model and checks the connection during initialization. The surrounding function reports and re-raises initialization errors.
model_name = os.getenv("OLLAMA_MODEL", "llama3")
llm = OllamaLLM(model=model_name)
# Test the connection
test_response = llm.invoke("Hello") # Updated to use invoke
return llmScope & practical notes
- A relevance score or a fluent answer still needs a human check.