Agents¶
Agents are the core building blocks of AgentiCraft. An agent is an AI-powered entity that can reason, use tools, and maintain memory.
What is an Agent?¶
An agent in AgentiCraft consists of:
- Identity: Name and instructions that define its purpose
- Reasoning: Transparent thought processes
- Tools: Capabilities it can use
- Memory: Context it maintains
- Provider: The LLM that powers it
Creating Agents¶
Basic Agent¶
from agenticraft import Agent
agent = Agent(
name="Assistant",
instructions="You are a helpful AI assistant."
)
Agent with Tools¶
from agenticraft import Agent, tool
@tool
def search(query: str) -> str:
"""Search for information."""
# Implementation here
return f"Results for: {query}"
agent = Agent(
name="Researcher",
instructions="You help with research tasks.",
tools=[search]
)
Agent with Memory¶
from agenticraft import Agent, ConversationMemory
agent = Agent(
name="ChatBot",
instructions="You are a conversational assistant.",
memory=[ConversationMemory(max_turns=10)]
)
Agent Configuration¶
agent = Agent(
name="Advanced",
model="gpt-4",
temperature=0.7,
max_tokens=2000,
timeout=30,
max_retries=3
)
Using Agents¶
Synchronous Usage¶
Asynchronous Usage¶
Understanding Agent Responses¶
Every agent response includes:
content
: The final responsereasoning
: The thought processtool_calls
: Any tools usedusage
: Token usage information
Best Practices¶
- Clear Instructions: Be specific about the agent's role
- Appropriate Tools: Only include necessary tools
- Memory Management: Use memory judiciously
- Error Handling: Always handle potential errors