Can I build an AI agent without using a framework?
How to Do It
You can call an LLM API directly from a script, manage the conversation history yourself, and implement tool use by parsing the model's output and executing functions. This gives you full control and avoids framework overhead. Many developers start this way to understand the core mechanics before adopting a framework.
For simple agents, a few hundred lines of Python can handle prompting, memory, and tool calls. You'll need to handle error handling, retries, and state management manually, but this can be simpler for narrow use cases.
- Use direct API calls to OpenAI, Anthropic, etc.
- Implement your own prompt templates and parsing
- Manage conversation history in a list or database
- Write custom logic for tool selection and execution
When to Consider a Framework
Frameworks like LangChain or LlamaIndex provide abstractions for common patterns (e.g., RAG, multi-agent coordination) and integrations with many tools. They can speed up development for complex agents, but they also add dependencies and learning curves. If your agent is simple or you need fine-grained control, going framework-free is viable.
Evaluate based on your team's familiarity, the complexity of your agent, and long-term maintenance. Some production teams prefer minimal dependencies for reliability.
Common mistakes
- Believing frameworks are mandatory—they are not; many production agents use custom code.
- Overlooking the maintenance burden of custom code, which can grow as the agent scales.
- Assuming frameworks always save time; for simple agents, they can add unnecessary complexity.
