Close Menu
    Trending
    • Is Your AI Whispering Secrets? How Scientists Are Teaching Chatbots to Forget Dangerous Tricks | by Andreas Maier | Jul, 2025
    • Qantas data breach to impact 6 million airline customers
    • He Went From $471K in Debt to Teaching Others How to Succeed
    • An Introduction to Remote Model Context Protocol Servers
    • Blazing-Fast ML Model Serving with FastAPI + Redis (Boost 10x Speed!) | by Sarayavalasaravikiran | AI Simplified in Plain English | Jul, 2025
    • AI Knowledge Bases vs. Traditional Support: Who Wins in 2025?
    • Why Your Finance Team Needs an AI Strategy, Now
    • How to Access NASA’s Climate Data — And How It’s Powering the Fight Against Climate Change Pt. 1
    AIBS News
    • Home
    • Artificial Intelligence
    • Machine Learning
    • AI Technology
    • Data Science
    • More
      • Technology
      • Business
    AIBS News
    Home»Machine Learning»Pydantic AI: AI Agent Library. AI agents is an evolving landscape in… | by Naresh Kancharla | Dec, 2024
    Machine Learning

    Pydantic AI: AI Agent Library. AI agents is an evolving landscape in… | by Naresh Kancharla | Dec, 2024

    Team_AIBS NewsBy Team_AIBS NewsDecember 25, 2024No Comments3 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    AI brokers is an evolving panorama in AI Improvement and discovering a proper device which adapts and open sufficient for the longer term necessities makes a distinction. Pydantic AI library is highly effective AI agent library constructed by the crew behind the favored Pydantic information validation library

    Pydantic AI is an agentic framework designed to simplify the method of making and managing AI brokers. It builds upon the strong basis of the Pydantic library, which is broadly used for information validation and kind checking in Python initiatives.

    pip set up pydantic-ai

    If you already know which mannequin you’re going to make use of and need to keep away from putting in superfluous packages, you should utilize the pydantic-ai-slim bundle.

    pip set up pydantic-ai-slim 

    Creating an agent is easy, requiring only a few strains of code. You may outline an agent by specifying the mannequin identify and a system immediate.

    from pydantic_ai import Agent

    agent = Agent(
    'ollama:llama3'
    #system_prompt='Be concise, reply with one sentence.',
    )

    consequence = agent.run_sync('The place have been the olympics held in 2012 ?')
    print(consequence.information)

    """

    The Olympics held in 2012 have been the Summer season Olympics, formally often known as the
    Video games of the XXX Olympiad. They occurred in London, United Kingdom,
    from July 27 to August 12, 2012. The Paralympic Video games adopted
    from August 29 to September 9, 2012, additionally in London.
    """

    Harnesses the facility of Pydantic to validate and structure mannequin outputs, making certain responses are constant throughout runs.

    from pydantic import BaseModel
    from pydantic_ai import Agent

    class CityLocation(BaseModel):
    metropolis: str
    nation: str

    agent = Agent('ollama:llama3.2', result_type=CityLocation)

    consequence = agent.run_sync('Which metropolis and nation have been the olympics held in 2012?')
    print(consequence.information)

    """

    metropolis='London' nation='United Kingdom'
    """

    Operate instruments present a mechanism for fashions to retrieve further info to assist them generate a response.

    There are a variety of the way to register instruments with an agent:

    • by way of the @agent.tool decorator — for instruments that want entry to the agent context
    • by way of the @agent.tool_plain decorator — for instruments that don’t want entry to the agent context
    • by way of the tools key phrase argument to Agent which might take both plain capabilities, or situations of Tool

    @agent.device is taken into account the default decorator since within the majority of instances instruments will want entry to the agent context.

    import random

    from pydantic_ai import Agent, RunContext

    agent = Agent(
    'ollama:llama3.2',
    deps_type=str,
    system_prompt=(
    "You are a cube sport, you need to roll the die and see if the quantity "
    "you get again matches the person's guess. If that's the case, inform them they are a winner. "
    "Use the participant's identify within the response."
    ),
    )

    @agent.tool_plain
    def roll_die() -> str:
    """Roll a six-sided die and return the consequence."""
    return str(random.randint(1, 6))

    @agent.device
    def get_player_name(ctx: RunContext[str]) -> str:
    """Get the participant's identify."""
    return ctx.deps

    dice_result = agent.run_sync('My guess is 4', deps='Anne')
    print(dice_result.information)



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleRobot Holiday Videos – IEEE Spectrum
    Next Article Understanding When and How to Implement FastAPI Middleware (Examples and Use Cases) | by Mike Huls | Dec, 2024
    Team_AIBS News
    • Website

    Related Posts

    Machine Learning

    Is Your AI Whispering Secrets? How Scientists Are Teaching Chatbots to Forget Dangerous Tricks | by Andreas Maier | Jul, 2025

    July 2, 2025
    Machine Learning

    Blazing-Fast ML Model Serving with FastAPI + Redis (Boost 10x Speed!) | by Sarayavalasaravikiran | AI Simplified in Plain English | Jul, 2025

    July 2, 2025
    Machine Learning

    From Training to Drift Monitoring: End-to-End Fraud Detection in Python | by Aakash Chavan Ravindranath, Ph.D | Jul, 2025

    July 1, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    Is Your AI Whispering Secrets? How Scientists Are Teaching Chatbots to Forget Dangerous Tricks | by Andreas Maier | Jul, 2025

    July 2, 2025

    I Tried Buying a Car Through Amazon: Here Are the Pros, Cons

    December 10, 2024

    Amazon and eBay to pay ‘fair share’ for e-waste recycling

    December 10, 2024

    Artificial Intelligence Concerns & Predictions For 2025

    December 10, 2024

    Barbara Corcoran: Entrepreneurs Must ‘Embrace Change’

    December 10, 2024
    Categories
    • AI Technology
    • Artificial Intelligence
    • Business
    • Data Science
    • Machine Learning
    • Technology
    Most Popular

    How to Avoid the Perils of Short-Term Thinking For Long-Term Success

    April 19, 2025

    Building a Movie Recommender System: A Content-Based Approach | by Divyesh Sarvaiya | Jan, 2025

    January 10, 2025

    In the TikTok Show ‘Famehungry,’ All the World’s an Audience

    January 24, 2025
    Our Picks

    Is Your AI Whispering Secrets? How Scientists Are Teaching Chatbots to Forget Dangerous Tricks | by Andreas Maier | Jul, 2025

    July 2, 2025

    Qantas data breach to impact 6 million airline customers

    July 2, 2025

    He Went From $471K in Debt to Teaching Others How to Succeed

    July 2, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Business
    • Data Science
    • Machine Learning
    • Technology
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2024 Aibsnews.comAll Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.