Saturday, March 15, 2025

#2 - Basic Agent

 Example 2: Creating a Basic Agent with Metrics

Step 1: Create basic_agent.py

Create a new file named basic_agent.py and add the following code:

from agno.agent import Agent, RunResponse  # noqa
from agno.models.ollama import Ollama
from agno.tools.yfinance import YFinanceTools
from ollama import Client as OllamaClient

agent = Agent(
    model=Ollama(id="llama3.2", client=OllamaClient()),
    tools=[YFinanceTools(stock_price=True)],
    markdown=True,
)

# Print the response in the terminal
agent.print_response("Share a 2 sentence joke on quantum computing")
print(agent.run_response.metrics)


Step 2: Run the Script

python basic_agent.py

Expected Response

Response:

It seems like the previous response didn't quite work out as expected. Here's another attempt at a 2-sentence joke about quantum computing:    

Why did the qubit go to therapy? It was struggling to stay in its superposition of emotions! 

{'input_tokens': [193, 116], 'output_tokens': [152, 51], 'total_tokens': [345, 167], 'prompt_tokens': [0, 0], 'completion_tokens': [0, 0], 'additional_metrics': [{'total_duration': 15560175500, 'load_duration': 19980900, 'prompt_eval_duration': 4270000000, 'eval_duration': 11266000000}, {'total_duration': 5288854300, 'load_duration': 24048600, 'prompt_eval_duration': 1524000000, 'eval_duration': 3737000000}], 'time': [15.564438400000654, 5.28971300000012]}

Understanding the Metrics

  • Input and Output Tokens: The number of tokens processed.
  • Total Tokens: The sum of input and output tokens.
  • Additional Metrics: Execution duration in nanoseconds.
  • Time: Execution time in seconds.

Conclusion

These examples provide a solid foundation for working with Agno agents. You can build upon these scripts by adding more tools, modifying prompts, or integrating additional AI capabilities. Happy coding!

Stay tuned for more tutorials on AI-driven automation!

No comments:

Post a Comment

#5 - Structured-Output

 Example 5: Structured Output  Step 1: Create structured_ouput.py from agno . agent import Agent from pydantic import BaseModel , Fiel...