This guide covers the most common patterns you’ll need when working with OmniCoreAgent — from running your first query to handling errors in production.
Every interaction starts with agent.run(). It returns a dictionary with the agent’s response and metadata.
import asynciofrom omnicoreagent import OmniCoreAgentasync def main(): agent = OmniCoreAgent( name="my_agent", system_instruction="You are a helpful assistant.", model_config={"provider": "openai", "model": "gpt-4o"} ) result = await agent.run("What is the capital of France?") print(result["response"]) # The agent's text reply print(result["session_id"]) # Session used for this run print(result.get("metric")) # Token/timing metric when provider usage is available await agent.cleanup()asyncio.run(main())
Use session_id to give your agent persistent memory across multiple calls. Without it, each call is stateless.
# First interaction — agent learns the user's nameawait agent.run("My name is Abiola.", session_id="user_42")# Later interaction — agent remembersresult = await agent.run("What's my name?", session_id="user_42")# → "Your name is Abiola."
Keep external integrations outside the core package. Use MCP servers for shared
capabilities, or wrap project-owned APIs with ToolRegistry when the tool is
specific to your application.
Wrap agent calls with try/except for production use:
from omnicoreagent.exceptions import OmniCoreAgentErrortry: result = await agent.run("Analyze this dataset", session_id="user_1")except OmniCoreAgentError as e: print(f"Agent runtime error: {e.message}")except Exception as e: print(f"Unexpected failure: {e}")