Skip to main content
Planned Feature — Coming Soon

🚧 This feature is not yet released. The documentation below describes planned behavior and may change before launch.

Building Your First Agent

A step-by-step guide to creating a production-ready agent from scratch. We'll build a Company Research Agent that takes a company name and returns a structured profile.

What We'll Build​

An agent that:

  1. Accepts a company name and optional parameters
  2. Searches the web for information
  3. Visits the company website
  4. Returns a structured JSON profile

Step 1: Plan Your Inputs​

Start by deciding what data the agent needs. Think about who will use it:

  • If just you — keep inputs minimal
  • If marketplace — think about what different users would want to customize
from flymyai import AgentClient

client = AgentClient(api_key="fly-***")

input_schema = {
"type": "object",
"properties": {
"company_name": {
"type": "string",
"description": "Company to research"
},
"focus": {
"type": "string",
"enum": ["general", "financials", "product", "team", "competitors"],
"default": "general",
"description": "What aspect to focus on"
},
"depth": {
"type": "string",
"enum": ["brief", "standard", "thorough"],
"default": "standard",
"description": "Level of research depth"
}
},
"required": ["company_name"]
}

Step 2: Write the Goal with Templating​

Use Handlebars to inject inputs into the goal. Think of it as building a dynamic prompt:

goal = """Research {{ company_name }} and create a comprehensive company profile.

Research focus: {{ focus }}.
Depth level: {{ depth }}.

{{#if focus}}
{{#if (eq focus "financials")}}
Prioritize: revenue, funding rounds, valuation, growth metrics, and financial health indicators.
{{/if}}
{{#if (eq focus "product")}}
Prioritize: core products, pricing, technology stack, unique features, and product roadmap.
{{/if}}
{{#if (eq focus "competitors")}}
Prioritize: identifying top 5 competitors, comparative strengths/weaknesses, market positioning.
{{/if}}
{{/if}}

Return a structured profile with all findings, clearly sourced."""

Step 3: Define Output Schema​

Structured output makes the agent predictable and integrable:

output_schema = {
"type": "object",
"properties": {
"company": {
"type": "object",
"properties": {
"name": {"type": "string"},
"website": {"type": "string"},
"industry": {"type": "string"},
"founded": {"type": "string"},
"headquarters": {"type": "string"},
"employee_count": {"type": "string"},
"description": {"type": "string"}
}
},
"key_findings": {
"type": "array",
"items": {
"type": "object",
"properties": {
"category": {"type": "string"},
"finding": {"type": "string"},
"source": {"type": "string"}
}
}
},
"summary": {"type": "string"},
"sources": {
"type": "array",
"items": {"type": "string"}
}
}
}

Step 4: Create the Agent​

agent = client.agents.create(
name="Company Profiler",
goal=goal,
tools=["web_search", "browse_website", "news_search"],
model="anthropic/default",
input_schema=input_schema,
output_schema=output_schema,
instructions={
"planning": "1) Search for the company. 2) Visit their website. 3) Check recent news. 4) Compile findings.",
"tool_calling": "Always visit the company's official website. Cross-reference claims across 2+ sources.",
"formatting": "Cite sources for every key finding."
}
)

print(f"Agent created: {agent.id}")

Step 5: Test with Different Inputs​

Test with minimal input (required fields only):

run1 = client.runs.create(
agent_id=agent.id,
input={"company_name": "Stripe"}
)
result1 = client.runs.wait(run1.id)
print(result1.output["summary"])

Test with all fields:

run2 = client.runs.create(
agent_id=agent.id,
input={
"company_name": "Stripe",
"focus": "financials",
"depth": "thorough"
}
)
result2 = client.runs.wait(run2.id)
print(result2.output["key_findings"])

Step 6: Iterate​

Review the output. Common improvements:

IssueFix
Missing informationAdd more specific instructions in planning
Wrong sourcesTighten tool_calling instructions
Poor formattingAdjust formatting instructions or output schema
Too slowReduce depth default, use faster model
HallucinationsAdd "Only include verified, sourced claims" to instructions
client.agents.update(
agent_id=agent.id,
instructions={
"planning": "Updated planning instructions...",
"tool_calling": "Only cite information from pages you actually visited.",
"formatting": "Every finding MUST have a source URL."
}
)

Step 7: Publish (Optional)​

Happy with the results? Publish for production use or marketplace:

# For personal production use
client.agents.publish(agent_id=agent.id)

# Or for marketplace
client.agents.update(
agent_id=agent.id,
visibility="public",
pricing={"per_run": 0.50}
)
client.agents.publish(agent_id=agent.id)

Complete Code​

from flymyai import AgentClient

client = AgentClient(api_key="fly-***")

# Create agent
agent = client.agents.create(
name="Company Profiler",
goal="""Research {{ company_name }} and create a comprehensive company profile.
Research focus: {{ focus }}. Depth: {{ depth }}.
Return a structured profile with all findings, clearly sourced.""",
tools=["web_search", "browse_website", "news_search"],
input_schema={
"type": "object",
"properties": {
"company_name": {"type": "string", "description": "Company to research"},
"focus": {
"type": "string",
"enum": ["general", "financials", "product", "team", "competitors"],
"default": "general"
},
"depth": {
"type": "string",
"enum": ["brief", "standard", "thorough"],
"default": "standard"
}
},
"required": ["company_name"]
},
output_schema={
"type": "object",
"properties": {
"company": {"type": "object", "properties": {
"name": {"type": "string"},
"website": {"type": "string"},
"industry": {"type": "string"},
"description": {"type": "string"}
}},
"key_findings": {"type": "array", "items": {"type": "object", "properties": {
"category": {"type": "string"},
"finding": {"type": "string"},
"source": {"type": "string"}
}}},
"summary": {"type": "string"},
"sources": {"type": "array", "items": {"type": "string"}}
}
}
)

# Run
run = client.runs.create(agent_id=agent.id, input={"company_name": "Stripe"})
result = client.runs.wait(run.id)
print(result.output)

Next Steps​