Login Agent to remote asterisk server

I am using Asterisk 1.4.0 from source. I have a main Asterisk server and a Branch Asterisk server. The two are connected with SIP (via sip.conf provided below) and I would like the main server to handle the login/logout of Agents which are in the branch server.

main’s sip.conf
[mainserver]
type=user
md5secret=the md5 encrypted password
host= this server
disallow=all
allow=ulaw
canreinvite=no
context=testing-main

[tobranchserver]
type=peer
host= the branch server
fromuser=branchserver
username=branchserver
md5secret=the md5 encrypted password
disallow=all
allow=ulaw
canreinvite=no

branch’s sip.conf
[branchserver]
type=user
md5secret= the md5 encrypted password
host= this server
disallow=all
allow=ulaw
canreinvite=no
context=testing-branch

[tomainserver]
type=peer
host= the main server
fromuser=mainserver
username=mainserver
md4secret= the md5 encrypted password
disallow=all
allow=ulaw
canreinvite=no

main’s extensions.conf (shows working connectivity)
[testing-main]
exten = 444,1,Dial(SIP/tobranchserver/${exten})
exten = 444,n,Hangup()

branch’s extensions.conf
[testing-branch]
exten = 444,1,Answer()
exten = 444,n,Playback(tt-monkeys)
exten = 444,n,Hangup()

Not sure what your actual question/issue it but this can be done.

branch system:
exten => 1234,1,Dial(Sip/${EXTEN}@mainserver)
exten => 1002,1,Dial(Sip/agents_phone)

main system:
exten => 1234,1,AddQueueMember(support|local/${CALLERIDNUM}@agents/n)

[agents]
exten => _XXXX,1,Dial(Sip/${EXTEN}@branchserver)