Implementation:24mlight A Share investment Agent agent endpoint
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Software_Engineering, Observability |
| Last Updated | 2026-10-10 14:00 GMT |
Overview
Concrete tool for wrapping agent functions with automatic state tracking, stdout/stderr capture, log storage, and trace logging via a decorator pattern, provided by the A_Share_investment_Agent repository.
Description
The agent_endpoint decorator transforms a plain agent function into a fully monitored component. When applied, it:
- Registers the agent in
api_state - Sets agent state to "running" before execution, "completed" or "error" after
- Serializes and stores input/output AgentState
- Captures stdout/stderr during execution
- Stores reasoning details in api_state
- Writes per-agent trace files when
trace_diris set - Creates
AgentExecutionLogentries inBaseLogStorage
Usage
Import when you need to:
- Add monitoring and observability to agent functions
- Capture execution state, stdout, and LLM interactions automatically
Code Reference
Source Location
- Repository: A_Share_investment_Agent
- File: src/utils/api_utils.py
- Lines: L273-491
Signature
def agent_endpoint(agent_name: str, description: str = ""):
"""
Decorator for creating monitored agent endpoints.
Usage:
@agent_endpoint("sentiment", "情绪分析师")
def sentiment_agent(state: AgentState) -> AgentState:
...
"""
Import
from src.utils.api_utils import agent_endpoint
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| agent_name | str | Yes | Unique agent identifier |
| description | str | No | Human-readable description |
Outputs
| Name | Type | Description |
|---|---|---|
| return | Callable | Decorated function with monitoring |
Usage Examples
Basic Decoration
from src.utils.api_utils import agent_endpoint
from src.agents.state import AgentState
@agent_endpoint("my_agent", "Custom analysis agent")
def my_agent(state: AgentState) -> dict:
# Agent logic here
result = do_analysis(state["data"])
return {
"messages": [HumanMessage(content=json.dumps(result), name="my_agent")],
"data": state["data"],
"metadata": state["metadata"],
}
# Agent is now registered in api_state and monitored
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment