Building AI agents, atomically
Key Modules
Last Updated: 2026-10-21
Core framework — atomic-agents/atomic_agents/
agents
- Location:
atomic-agents/atomic_agents/agents/atomic_agent.py - Purpose: The
AtomicAgent[InputSchema, OutputSchema]class andAgentConfig. Orchestrates the run lifecycle (sync / stream / async), context-provider registration, hook registration, and context-window trimming. - Exposes:
AtomicAgent,AgentConfig,BasicChatInputSchema,BasicChatOutputSchema. - Depends on:
base/,context/,utils/,instructor.
base
- Location:
atomic-agents/atomic_agents/base/ - Purpose: The typed contracts everything else implements.
- Key files:
base_io_schema.py(BaseIOSchema— Pydantic base; non-empty docstring enforced and used as the schema description),base_tool.py(BaseTool[In, Out],BaseToolConfig),base_resource.py(BaseResource),base_prompt.py(BasePrompt), andmultimodal.py(VideoURL— OpenAI-compatiblevideo_urlcontent-part model for video inputs). - Exposes via package root:
BaseIOSchema,BaseTool,BaseToolConfig,VideoURL.
context
- Location:
atomic-agents/atomic_agents/context/ - Purpose: System-prompt assembly and conversation memory.
- Key files:
system_prompt_generator.py(SystemPromptGenerator,BaseDynamicContextProvider),base_chat_history.py(BaseChatHistory— interface-only ABC declaring the memory contractAtomicAgentdepends on; the pluggable seam for custom/persistent backends),chat_history.py(ChatHistory,Message— the built-in in-memory implementation ofBaseChatHistory: multimodal Image/Audio/PDF plusVideoURL, turn grouping,dump()/load()serialization). - Note:
AgentConfig.historyis typed toBaseChatHistory, so any conforming backend drops in.
connectors/mcp
- Location:
atomic-agents/atomic_agents/connectors/mcp/ - Purpose: Model Context Protocol integration — expose MCP server tools/resources/prompts as Atomic Agents components.
- Exposes:
MCPFactory,MCPDefinitionService,SchemaTransformer,fetch_mcp_tools/fetch_mcp_resources/fetch_mcp_prompts(sync + async).
utils
- Location:
atomic-agents/atomic_agents/utils/ - Key files:
token_counter.py(TokenCountervia LiteLLM;get_context_token_count),format_tool_message.py.
observability (opt-in)
- Location:
atomic-agents/atomic_agents/observability/ - Purpose: plain OpenTelemetry tracing for any backend (OTLP collector, Grafana Tempo, Sentry, Datadog,
Honeycomb, PostHog, Arize Phoenix, Langfuse). Only
opentelemetry-apiis required; the OpenTelemetry GenAI semantic-convention attributes are primary and the OpenInference family is an optional layer, auto-on when theopeninference-instrumentationpackage is importable (phoenixextra). - Modules:
__init__.py(loader,AtomicAgentsInstrumentor, stdlib-only imports),tracing.py(thin facade),tracing_config.py(TracingConfig,PayloadVisibility, env parsing),span_payloads.py(serialize, hide before serialize, truncate with<key>.original_length, bounded/redacted error text),span_attributes.py(key constants, Instructor-to-semconv provider map, None filtering, best-effort attribute collection, OpenInference context seam,using_conversation),agent_spans.py(fourAtomicAgent.run*wrappers, stream cursors, run state),tool_spans.py(BaseToolwrappers via__subclasses__walk + wrapped__init_subclass__, re-entrancy guard),installation.py(install / uninstall / replace-in-place),llm_attempt_spans.py(Instructor hook handlers). - Contract:
instrument(tracer_provider=, config=TracingConfig | PayloadVisibility | None, **options)/uninstrument()/is_instrumented_by_opentelemetry. Same arguments: no-op; different provider or config: replaced in place with a WARNING,Nonekeeps the installed value; in-flight spans finish on their original provider. Hooks are registered once per Instructor client under a lock and removed on uninstall;suppress_instrumentationis honored; hooks never raise into user code. - Spans:
invoke_agent {AgentConfig.name or class}(gen_ai.operation.name=invoke_agent,gen_ai.agent.name,gen_ai.request.model,gen_ai.provider.name,gen_ai.conversation.id,atomic_agents.agent.class,.input,.output, model/mode/schema/history/provider/prompt-hash keys, usage totals andatomic_agents.llm.attemptsat end);execute_tool {tool.tool_name}(gen_ai.tool.*,atomic_agents.tool.class); onechat {model}CLIENT span per Instructor attempt fromcompletion:kwargs/completion:response/completion:errorwith per-attempt usage (cached/reasoning tokens for both chat-completion and Responses shapes),parse:erroras avalidation_errorevent;error.typeon failures; cancellation =atomic_agents.cancelled, never ERROR. Spans always attach to the current context.llm_spans=Falsekeeps totals and drops chat spans. - Config:
TracingConfig(hide_inputs, hide_outputs, max_attribute_length=4096, openinference_attributes=None, llm_spans=True); envATOMIC_AGENTS_TRACE_HIDE_INPUTS/_OUTPUTS(fallbackOPENINFERENCE_HIDE_*),ATOMIC_AGENTS_TRACE_MAX_ATTRIBUTE_LENGTH(tolerant, 4096 fallback),ATOMIC_AGENTS_TRACE_LLM_SPANS. Underhide_outputsevery exception becomes<Type>: <N> attempts (__REDACTED__). Nothing inatomic_agents/__init__.pyimports the package. - Tests:
atomic-agents/tests/observability/(in-memory exporter;instructor_transport.pybuilds real Instructor clients overhttpx.MockTransport;test_instructor_modes.pycovers TOOLS/JSON/JSON_SCHEMA/RESPONSES_TOOLS).
Subprojects
atomic-assembler (CLI)
- Location:
atomic-assembler/atomic_assembler/ - Purpose: Textual TUI to browse and install forge tools into a user project.
- Key files:
main.py(main(); argparse--enable-logging,--version),app.py(AtomicAssembler(App)),screens/(main_menu,atomic_tool_explorer,file_explorer,tool_info_screen),widgets/,utils.py(GithubRepoCloner,AtomicToolManager),constants.py(GitHub URL,TOOLS_SUBFOLDER).
atomic-forge (tools)
- Location:
atomic-forge/tools/ - Purpose: Standalone tools, each an independent mini-project following the
BaseToolpattern, copied into user projects by the assembler (build files such aspyproject.toml/requirements.txt/uv.lockare skipped on copy). - Recent additions:
firecrawl_searchprovides web/news search;fxmacrodataprovides economic releases, FX and COT data. Both keep their own dependencies and setup. - YouTube compatibility:
youtube_transcript_scraperuses the instance-based transcript API and converts SDK transcript objects to raw entries. - Authoring guide:
atomic-forge/guides/tool_structure.md.
atomic-examples
- Location:
atomic-examples/ - Purpose: 16 runnable reference apps. Catalog in
entry-points.md.