How junlinghu/agent-code works
Project Type and Purpose
• This is an open-source collection of Python “agent” scripts that illustrate how to build LLM-based agents from scratch (no frameworks).
• Each script (agent_toolcall, agent_searchWeb, agent_computer, agent_kb) demonstrates a different tool-calling capability (generic tool, web search, local OS commands, knowledge-base lookup).
• A client.py file glues everything together by taking user input, selecting/running an agent, and returning the answer.
Key Components
a. Client Interface (client.py)
b. Core Agent Engine (abstract Agent class or logic shared by agent_*.py)
c. LLM Service (OpenAI API, with API token from environment)
d. Tool Adapters:
• ToolCaller (agent_toolcall.py)
• WebSearch (agent_searchWeb.py → external search API)
• LocalComputer (agent_computer.py → OS commands)
• KnowledgeBase (agent_kb.py → reads kb.json)
e. Knowledge Base Storage (kb.json)
f. External Services:
• OpenAI LLM endpoint
• Web search API endpoint
• Operating system shell
Relationships and Data Flows
1. User issues a query via client.py
2. client.py instantiates the chosen agent module
3. Agent formats prompt and calls the OpenAI API (reads API token from environment)
4. LLM returns a response that often includes an instruction to call a tool
5. Agent dispatches to the appropriate Tool Adapter
• WebSearch → issues HTTP request to search API → parses results
• LocalComputer → executes shell commands → captures stdout
• KnowledgeBase → loads & searches kb.json → returns matched content
• Generic ToolCaller → calls an abstract “tool” interface
6. Agent receives tool output, may re-prompt the LLM for final answer
7. client.py prints or returns the answer to the user
Architectural Patterns and Principles
• Modular design: each tool is encapsulated in its own script/module following a consistent interface
• Separation of concerns: client (I/O) ↔ agent logic (LLM orchestration) ↔ tool adapters ↔ data/external services
• Extensibility: new agent_*.py modules can be added by implementing the same call/response pattern